import {Component, ViewChild} from '@angular/core';
import {Content, IonicPage, NavController, NavParams} from 'ionic-angular';
import {SideMenuService} from "../../../services/common/side-menu.service";
import {MemberPerformanceProvider} from "../../../providers/perfomance/member-performance/member-performance.provider";
import {LoadingService} from "../../../services/common/loading.service";


@IonicPage()
@Component({
    selector: 'page-member-performance',
    templateUrl: 'member-performance.html',
    providers: [
        SideMenuService,
        MemberPerformanceProvider,
        LoadingService
    ]
})
export class MemberPerformancePage {
    private memberPerData=[];
    isScrolling = false;
    parms={
        'groupId':'',
        'groupType':''
    };
    isLoaded:boolean = false;
    @ViewChild(Content) content: Content;
    constructor(public navCtrl: NavController,
                public navParams: NavParams,
                private sideMenuService: SideMenuService,
                private memberProvider:MemberPerformanceProvider,
                public load:LoadingService
                ) {
        this.parms={
            'groupId':this.navParams.get('groupId'),
            'groupType':this.navParams.get('groupType')
        };
        this.getMemberPerformance(this.parms);
    }




    ionViewDidLoad() {

    }


    /**
     * 回到顶部
     */
    goUp() {
        if (this.isScrolling) {
            setTimeout(() => {
                this.goUp();
            }, 300);
            return;
        }
        this.content.scrollToTop();
    }

    scrollStart(e) {
        this.isScrolling = true;
    }

    scrollEnd(e) {
        this.isScrolling = false;
    }


    /**
     * 获取团队成员历史业绩
     */
    getMemberPerformance(parms){
        this.isLoaded =false;
        this.load.showLoading();
        this.memberProvider.getMenberPer(parms).subscribe((res)=>{
            this.memberPerData = res;
            this.isLoaded =true;
            this.load.dismissLoading();
        },error=>{
            this.load.dismissLoading();
        });

    }

    /**
     * 打开菜单
     * @param myEvent
     */
    openMenu(myEvent) {
        this.sideMenuService.openSideMenu(myEvent)
    }

    /**
     * 返回
     * @param ev
     */
    backButtonClick(ev) {
        ev.preventDefault();
        ev.stopPropagation();
        this.navCtrl && this.navCtrl.pop(null, null);
    }
}
